<?php
namespace Badmins\Model;
use Think\Model;
class WxMenuModel extends Model{
	protected $_validate = array(
			array('name','require','菜单名称必须'),
			array('action','ckaction','微信菜单相关动作填写错误',1,'callback',3),
			array('url','url','url填写错误',2),
	);
	protected $_auto = array (
			array ('status_id','ckstatus',3,'callback',1),
	);
	public function ckaction(){
		$action = I('action/d');
		$keyword_id = I('keyword_id');
		if($action){
			switch ($action){
				case '1':
					if(empty($keyword_id)){
						return false;
					}else{
						return true;
					}
				break;
				case '2':
					return self::ckstatus();
				break;
				case '3':
					if(empty($_POST['url'])){
						return false;
					}else{
						return true;
					}
			}
		}else{
			return true;
		}
	}
	public function ckstatus(){
		$status = I('status');
		switch ($status){
			case '1':
				//文本
				if(empty($_POST['text_id'])){
					return false;
				}else{
					return $_POST['text_id'];
				}
			break;
			case '2':
				//图文
				if(empty($_POST['imgtxt_id'])){
					return false;
				}else{
					return $_POST['imgtxt_id'];
				}
			break;
			case '3':
				//语音
				if(empty($_POST['voice_id'])){
					return false;
				}else{
					return $_POST['voice_id'];
				}
			break;
			case '4':
				//视频
				if(empty($_POST['video_id'])){
					return false;
				}else{
					return $_POST['video_id'];
				}
			break;
			case '5':
				//图片
				if(empty($_POST['image_id'])){
					return false;
				}else{
					return $_POST['image_id'];
				}
			break;
			default:
				return 0;
			break;
		}
	}
}